package net.destroyer.game.tetris.core.gamespace;

import javax.media.j3d.BranchGroup;
import javax.media.j3d.Transform3D;
import javax.media.j3d.TransformGroup;
import javax.vecmath.Vector3f;

import net.destroyer.game.tetris.core.gamespace.util.Hash;

public class GameSpace extends BranchGroup {

	private Hash backplate;

	public GameSpace(int matrix, int height) {
		backplate = new Hash(matrix, matrix);
		this.addChild(backplate);

		TransformGroup tside = new TransformGroup();
		Transform3D tr1 = new Transform3D();
		tr1.rotX(Math.PI/2);
		tr1.setTranslation(new Vector3f(0,matrix/2f,height/2f));
		tside.setTransform(tr1);
		tside.addChild(new Hash(matrix, height));
		
		this.addChild(tside);
		
		TransformGroup tside2 = new TransformGroup();
		Transform3D tr2 = new Transform3D();
		tr2.rotX(Math.PI/2);
		tr2.setTranslation(new Vector3f(0,-(matrix/2f),height/2f));
		tside2.setTransform(tr2);
		tside2.addChild(new Hash(matrix, height));
		
		this.addChild(tside2);
		
		TransformGroup tside3 = new TransformGroup();
		Transform3D tr3 = new Transform3D();
		tr3.rotX(Math.PI/2);
		Transform3D tr31 = new Transform3D();
		tr31.rotZ(Math.PI/2);
		tr31.mul(tr3);
		tr31.setTranslation(new Vector3f(-(matrix/2f),0,height/2f));
		tside3.setTransform(tr31);
		tside3.addChild(new Hash(matrix, height));
		
		this.addChild(tside3);
		
		TransformGroup tside4 = new TransformGroup();
		Transform3D tr4 = new Transform3D();
		tr4.rotX(Math.PI/2);
		Transform3D tr41 = new Transform3D();
		tr41.rotZ(Math.PI/2);
		tr41.mul(tr4);
		tr41.setTranslation(new Vector3f((matrix/2f),0,height/2f));
		tside4.setTransform(tr41);
		tside4.addChild(new Hash(matrix, height));
		
		this.addChild(tside4);
		
		this.compile();
	}
}
